/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * HallRentingForm.java
 *
 * Created on 05 Nov 11, 12:54:30
 */
package Com.HallRenting_Case;

import Com.Entity.Karyawan;
import Com.Entity.TransaksiGedung;
import SistemPenyewaanKamar.MainController;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.sql.SQLException;
import java.util.GregorianCalendar;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;

/**
 *
 * @author Ignacio
 */
public class HallRentingForm extends javax.swing.JDialog {

    /** Creates new form HallRentingForm */
    public HallRentingForm(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();
        addWindowListener(new WindowAdapter() {

            @Override
            public void windowClosing(WindowEvent e) {
                TransaksiGedungController.exit(HallRentingForm.this, noSewaTextField1.getText());
            }
        });
        Karyawan kay = Karyawan.getusrID();
        idUserLabel.setText(kay.getUsername());
        TransaksiGedungController.showDateAndClock(jamLabel, tanggalLabel);
        sewaTabelInternal.setVisible(false);
        try {
            TransaksiGedung call;
            call = TransaksiGedung.getKoneksiKontrol();
            noSewaTextField1.setText(TransaksiGedungController.noTrans(call));
            noSewaTextField1.setEditable(false);
            totaltext.setEditable(false);
        } catch (FileNotFoundException ex) {
            Logger.getLogger(HallRentingForm.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IOException ex) {
            Logger.getLogger(HallRentingForm.class.getName()).log(Level.SEVERE, null, ex);
        } catch (SQLException ex) {
            Logger.getLogger(HallRentingForm.class.getName()).log(Level.SEVERE, null, ex);
        }
        sewaTabelInternal.setVisible(false);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        sewaTabelInternal = new javax.swing.JInternalFrame();
        jScrollPane1 = new javax.swing.JScrollPane();
        tabelSewa = new javax.swing.JTable();
        closeButton = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        jSeparator1 = new javax.swing.JSeparator();
        submitButton = new javax.swing.JButton();
        cancelButton = new javax.swing.JButton();
        jLabel13 = new javax.swing.JLabel();
        totaltext = new javax.swing.JTextField();
        jLabel14 = new javax.swing.JLabel();
        dataPenyewaPanel = new javax.swing.JPanel();
        namaTextField = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        noKTPTextField = new javax.swing.JTextField();
        jLabel15 = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();
        telpTextField = new javax.swing.JTextField();
        jLabel7 = new javax.swing.JLabel();
        jLabel16 = new javax.swing.JLabel();
        jenisIDCombo = new javax.swing.JComboBox();
        jamKeluarTextField = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        jamSewaTextField = new javax.swing.JTextField();
        jLabel12 = new javax.swing.JLabel();
        jLabel11 = new javax.swing.JLabel();
        jenisGedungCombo = new javax.swing.JComboBox();
        jadwalButton = new javax.swing.JButton();
        tglLahirChooser1 = new com.toedter.calendar.JDateChooser();
        tglSewaChooser = new com.toedter.calendar.JDateChooser();
        jLabel17 = new javax.swing.JLabel();
        dataTransaksiPanel = new javax.swing.JPanel();
        noSewaTextField1 = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        tanggalLabel = new javax.swing.JLabel();
        jamLabel = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        idUserLabel = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        jPanel1.setBackground(new java.awt.Color(255, 255, 255));
        jPanel1.setLayout(null);

        sewaTabelInternal.setMaximizable(true);
        sewaTabelInternal.setResizable(true);
        sewaTabelInternal.setTitle("Jadwal Sewa");
        sewaTabelInternal.getContentPane().setLayout(null);

        tabelSewa.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null}
            },
            new String [] {
                "TANGGAL SEWA", "NAMA PENYEWA", "JAM SEWA", "JAM KELUAR", "JENIS GEDUNG"
            }
        ));
        jScrollPane1.setViewportView(tabelSewa);

        sewaTabelInternal.getContentPane().add(jScrollPane1);
        jScrollPane1.setBounds(0, 0, 590, 190);

        closeButton.setText("Close");
        closeButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                closeButtonActionPerformed(evt);
            }
        });
        sewaTabelInternal.getContentPane().add(closeButton);
        closeButton.setBounds(260, 200, 90, 23);

        jPanel1.add(sewaTabelInternal);
        sewaTabelInternal.setBounds(10, 90, 615, 300);

        jLabel1.setFont(new java.awt.Font("Bookman Old Style", 1, 36));
        jLabel1.setText("Hall Renting Form");
        jLabel1.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jPanel1.add(jLabel1);
        jLabel1.setBounds(20, 30, 400, 60);
        jPanel1.add(jSeparator1);
        jSeparator1.setBounds(0, 120, 730, 10);

        submitButton.setText("SUBMIT");
        submitButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                submitButtonActionPerformed(evt);
            }
        });
        jPanel1.add(submitButton);
        submitButton.setBounds(580, 520, 90, 23);

        cancelButton.setText("KEMBALI KE MENU MAIN FORM");
        cancelButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cancelButtonActionPerformed(evt);
            }
        });
        jPanel1.add(cancelButton);
        cancelButton.setBounds(20, 520, 230, 23);

        jLabel13.setText("Total");
        jPanel1.add(jLabel13);
        jLabel13.setBounds(450, 480, 60, 20);
        jPanel1.add(totaltext);
        totaltext.setBounds(540, 480, 160, 20);

        jLabel14.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Com/HallRenting_Case/hall.jpg"))); // NOI18N
        jPanel1.add(jLabel14);
        jLabel14.setBounds(330, 0, 390, 120);

        dataPenyewaPanel.setBackground(new java.awt.Color(255, 255, 255));
        dataPenyewaPanel.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Data Penyewa", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Arial", 1, 12))); // NOI18N
        dataPenyewaPanel.setInheritsPopupMenu(true);
        dataPenyewaPanel.setLayout(null);
        dataPenyewaPanel.add(namaTextField);
        namaTextField.setBounds(150, 20, 280, 20);

        jLabel2.setText("Nama Penyewa");
        dataPenyewaPanel.add(jLabel2);
        jLabel2.setBounds(10, 20, 90, 20);
        dataPenyewaPanel.add(noKTPTextField);
        noKTPTextField.setBounds(150, 50, 280, 20);

        jLabel15.setText("No ID");
        dataPenyewaPanel.add(jLabel15);
        jLabel15.setBounds(10, 50, 90, 20);

        jLabel10.setText("No Telp / HP");
        dataPenyewaPanel.add(jLabel10);
        jLabel10.setBounds(10, 110, 70, 20);
        dataPenyewaPanel.add(telpTextField);
        telpTextField.setBounds(150, 110, 280, 20);

        jLabel7.setText("Tanggal Lahir");
        dataPenyewaPanel.add(jLabel7);
        jLabel7.setBounds(10, 140, 100, 20);

        jLabel16.setText("Jenis ID");
        dataPenyewaPanel.add(jLabel16);
        jLabel16.setBounds(10, 80, 90, 20);

        jenisIDCombo.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "--Pilih Jenis ID--", "KTP", "Passport" }));
        dataPenyewaPanel.add(jenisIDCombo);
        jenisIDCombo.setBounds(150, 80, 140, 20);
        dataPenyewaPanel.add(jamKeluarTextField);
        jamKeluarTextField.setBounds(340, 200, 90, 20);

        jLabel6.setText("Jam Keluar");
        dataPenyewaPanel.add(jLabel6);
        jLabel6.setBounds(260, 200, 90, 20);
        dataPenyewaPanel.add(jamSewaTextField);
        jamSewaTextField.setBounds(150, 200, 90, 20);

        jLabel12.setText("Jam Sewa");
        dataPenyewaPanel.add(jLabel12);
        jLabel12.setBounds(10, 200, 90, 20);

        jLabel11.setText("Jenis Gedung");
        dataPenyewaPanel.add(jLabel11);
        jLabel11.setBounds(10, 230, 90, 20);

        jenisGedungCombo.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "--Pilih Jenis Gedung--", "Ball Room", "Meeting Room" }));
        jenisGedungCombo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jenisGedungComboActionPerformed(evt);
            }
        });
        dataPenyewaPanel.add(jenisGedungCombo);
        jenisGedungCombo.setBounds(150, 230, 150, 20);

        jadwalButton.setText("Lihat Jadwal");
        jadwalButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jadwalButtonActionPerformed(evt);
            }
        });
        dataPenyewaPanel.add(jadwalButton);
        jadwalButton.setBounds(10, 280, 120, 23);

        tglLahirChooser1.setDateFormatString("dd MMM yyyy");
        dataPenyewaPanel.add(tglLahirChooser1);
        tglLahirChooser1.setBounds(150, 140, 150, 20);

        tglSewaChooser.setDateFormatString("dd MMM yyyy");
        dataPenyewaPanel.add(tglSewaChooser);
        tglSewaChooser.setBounds(150, 170, 150, 20);

        jLabel17.setText("Tanggal Sewa");
        dataPenyewaPanel.add(jLabel17);
        jLabel17.setBounds(10, 170, 100, 20);

        jPanel1.add(dataPenyewaPanel);
        dataPenyewaPanel.setBounds(10, 130, 490, 320);

        dataTransaksiPanel.setBackground(new java.awt.Color(255, 255, 255));
        dataTransaksiPanel.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Data Transaksi", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Arial", 1, 12))); // NOI18N
        dataTransaksiPanel.setLayout(null);
        dataTransaksiPanel.add(noSewaTextField1);
        noSewaTextField1.setBounds(90, 30, 110, 20);

        jLabel5.setText("No Sewa ");
        dataTransaksiPanel.add(jLabel5);
        jLabel5.setBounds(10, 30, 80, 20);

        jLabel9.setText("Tanggal");
        dataTransaksiPanel.add(jLabel9);
        jLabel9.setBounds(10, 90, 80, 20);

        jLabel3.setText("Jam");
        dataTransaksiPanel.add(jLabel3);
        jLabel3.setBounds(10, 120, 80, 20);
        dataTransaksiPanel.add(tanggalLabel);
        tanggalLabel.setBounds(90, 90, 110, 20);
        dataTransaksiPanel.add(jamLabel);
        jamLabel.setBounds(90, 120, 110, 20);

        jLabel8.setText("User ID ");
        dataTransaksiPanel.add(jLabel8);
        jLabel8.setBounds(10, 60, 80, 20);
        dataTransaksiPanel.add(idUserLabel);
        idUserLabel.setBounds(90, 60, 110, 20);

        jPanel1.add(dataTransaksiPanel);
        dataTransaksiPanel.setBounds(510, 130, 210, 320);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, 729, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, 562, Short.MAX_VALUE)
        );

        pack();
        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        java.awt.Dimension dialogSize = getSize();
        setLocation((screenSize.width-dialogSize.width)/2,(screenSize.height-dialogSize.height)/2);
    }// </editor-fold>//GEN-END:initComponents

    private void jadwalButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jadwalButtonActionPerformed
        // TODO add your handling code here:
        List<TransaksiGedung> jadwalList;
        try {
            jadwalList = TransaksiGedung.getKoneksiKontrol().getJadwal();
            jadwalTabelModel model = new jadwalTabelModel(jadwalList);
            tabelSewa.setModel(model);
            sewaTabelInternal.setVisible(true);
        } catch (FileNotFoundException ex) {
            Logger.getLogger(HallRentingForm.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IOException ex) {
            Logger.getLogger(HallRentingForm.class.getName()).log(Level.SEVERE, null, ex);
        } catch (SQLException ex) {
            Logger.getLogger(HallRentingForm.class.getName()).log(Level.SEVERE, null, ex);
        } catch (Exception ex) {
            JOptionPane.showMessageDialog(null, ex.getMessage() + "");
        }
    }//GEN-LAST:event_jadwalButtonActionPerformed

    private void closeButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_closeButtonActionPerformed
        // TODO add your handling code here:
        sewaTabelInternal.setVisible(false);
    }//GEN-LAST:event_closeButtonActionPerformed

    private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelButtonActionPerformed
        this.dispose();
        MainController.getFrame().setVisible(true);
        TransaksiGedungController.exit(HallRentingForm.this, noSewaTextField1.getText());
    }//GEN-LAST:event_cancelButtonActionPerformed

    private void submitButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_submitButtonActionPerformed
        // TODO add your handling code here:
        int stat = 0;
        try {
            stat = TransaksiGedungController.simpanButtonAction(tglLahirChooser1, tglSewaChooser,
                    idUserLabel, namaTextField, noKTPTextField, jenisIDCombo, noSewaTextField1,
                    jenisGedungCombo, jamSewaTextField, jamKeluarTextField, telpTextField, totaltext);
        } catch (Exception ex) {
            Logger.getLogger(HallRentingForm.class.getName()).log(Level.SEVERE, null, ex);
        }
        try {

            if (stat == 1) {
                TransaksiGedung call;
                call = TransaksiGedung.getKoneksiKontrol();
                noSewaTextField1.setText(TransaksiGedungController.noTrans(call));
                namaTextField.setText("");
                noKTPTextField.setText("");
                jenisIDCombo.setSelectedIndex(0);
                telpTextField.setText("");
                tglLahirChooser1.setDate(null);
                tglSewaChooser.setDate(null);
                jamSewaTextField.setText("");
                jamKeluarTextField.setText("");
                jenisGedungCombo.setSelectedIndex(0);
                totaltext.setText("");
            }
        } catch (FileNotFoundException ex) {
            Logger.getLogger(HallRentingForm.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IOException ex) {
            Logger.getLogger(HallRentingForm.class.getName()).log(Level.SEVERE, null, ex);
        } catch (SQLException ex) {
            Logger.getLogger(HallRentingForm.class.getName()).log(Level.SEVERE, null, ex);
        }

    }//GEN-LAST:event_submitButtonActionPerformed

    private void jenisGedungComboActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jenisGedungComboActionPerformed
        // TODO add your handling code here:
        TransaksiGedungController.hitungTotal(jamSewaTextField, jamKeluarTextField, totaltext, jenisGedungCombo, this);
    }//GEN-LAST:event_jenisGedungComboActionPerformed
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton cancelButton;
    private javax.swing.JButton closeButton;
    private javax.swing.JPanel dataPenyewaPanel;
    private javax.swing.JPanel dataTransaksiPanel;
    private javax.swing.JLabel idUserLabel;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel17;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JButton jadwalButton;
    private javax.swing.JTextField jamKeluarTextField;
    private javax.swing.JLabel jamLabel;
    private javax.swing.JTextField jamSewaTextField;
    private javax.swing.JComboBox jenisGedungCombo;
    private javax.swing.JComboBox jenisIDCombo;
    private javax.swing.JTextField namaTextField;
    private javax.swing.JTextField noKTPTextField;
    private javax.swing.JTextField noSewaTextField1;
    private javax.swing.JInternalFrame sewaTabelInternal;
    private javax.swing.JButton submitButton;
    private javax.swing.JTable tabelSewa;
    private javax.swing.JLabel tanggalLabel;
    private javax.swing.JTextField telpTextField;
    private com.toedter.calendar.JDateChooser tglLahirChooser1;
    private com.toedter.calendar.JDateChooser tglSewaChooser;
    private javax.swing.JTextField totaltext;
    // End of variables declaration//GEN-END:variables
}
